package com.cictec.middleware.core.controller;

import java.util.Date;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.cictec.middleware.core.entity.Bus;
import com.cictec.middleware.core.service.BusService;

@RestController
public class BusController {

	private static Logger logger = LoggerFactory.getLogger(BusController.class);
	
	@Autowired
	private BusService busService;

	/**
	 * 【数据库】获取所有车辆信息
	 * 
	 * @return
	 */
//	@RequestMapping(value = "/api/city", method = RequestMethod.POST)
	@RequestMapping(value = "/dc/bus")
	public List<Bus> selectListAllBus() {
		return busService.selectListAllBus();
	}

	/**
	 * 【数据库】查询当前所有在线车辆
	 * 
	 * @return
	 */
	@RequestMapping(value = "/dc/onlinebus")
	public List<Bus> selectListAllOnlineBus() {
		return busService.selectListAllOnlineBus();
	}

	/**
	 * 【数据库】根据线路查询车辆(查询所属线路下所有车辆)
	 * 
	 * @param lineUuid
	 * @return
	 */
	@RequestMapping(value = "/dc/bus/lineUuid/{lineUuid}")
	public List<Bus> selectBusByLineUuid(@PathVariable("lineUuid")String lineUuid) {
		return busService.selectBusByLineUuid(lineUuid);
	}

	/**
	 * 【数据库】查询车辆信息
	 * 
	 * @param busUuid
	 * @return
	 */
	@RequestMapping(value = "/dc/bus/busUuid/{busUuid}")
	public Bus selectBusByUuid(@PathVariable("busUuid")String busUuid) {
		Bus bus = busService.selectBusByUuid(busUuid);
		return bus;
	}

	/**
	 * 【数据库】根据设备编号查询车辆，包含devCode
	 * 
	 * @param devCode
	 * @return
	 */
	@RequestMapping(value = "/dc/bus/devCode/{devCode}")
	public Bus selectBusByDevCode(@PathVariable("devCode")String devCode) {
		return busService.selectBusByDevCode(devCode);

	}

	/**
	 * 【数据库】根据车牌号查询车辆，包含devCode
	 * 
	 * @param busNumber
	 * @return
	 */
	@RequestMapping(value = "/dc/bus/busNumber/{busNumber}")
	public Bus selectBusByBusNumber(@PathVariable("busNumber")String busNumber) {
		return busService.selectBusByBusNumber(busNumber);
	}

	/**
	 * 更新当前车辆司机
	 * 
	 * @param busUuid
	 * @param drvUuid
	 * @param loginTime
	 */
	@RequestMapping(value = "/dc/bus/updateBusLoginDriver")
	public void updateBusLoginDriver(@RequestParam("busUuid")String busUuid, @RequestParam("drvUuid")String drvUuid, @RequestParam("loginTime")Date loginTime) {

		busService.updateBusLoginDriver(busUuid, drvUuid, loginTime);
		logger.info("【busService】更新车辆表 {}, 司机{} 信息 ", busUuid, drvUuid);
	}

	/**
	 * 更新车辆的强制非运营状态
	 * 
	 * @param bus
	 */
	@RequestMapping(value = "/dc/bus/updateForceNonoperStatus")
	public void updateForceNonoperStatus(Bus bus) {
		busService.updateForceNonoperStatus(bus);

		logger.info("【busService】更新车辆表 {}, 设置 bus_force_non_oper :{} ", bus.getBusUuid(), bus.getBusForceNonOper());
	}

	/**
	 * 更新车辆所在线路
	 * 
	 * @param bus
	 */
	@RequestMapping(value = "/dc/bus/updateBusWorkingLine")
	public void updateBusWorkingLine(Bus bus) {
		busService.updateBusWorkingLine(bus);

		logger.info("【busService】更新车辆表 {}, 设置 bus_working_line_uuid:{} ", bus.getBusUuid(), bus.getBusWorkingLineUuid());
	}

}
